﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="~/hplus/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="~/hplus/css/animate.min.css" rel="stylesheet">
    <link href="~/hplus/css/style.min.css?v=4.0.0" rel="stylesheet">
    <link href="~/Xadmin/lib/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Xadmin/lib/layui/layui.js"></script>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Xadmin/js/xadmin.js"></script>
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" name="searContent" id="crReload" placeholder="请输入商品名" autocomplete="off">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" id="btncrReload" onclick="SelectName()" data-type="reload">搜索</button>
                            </div>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加配料单','/Produce/IngredientInput',470,500)">
                                <i class="layui-icon"></i>添加配料单
                            </button>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-hide" id="supplierTable" lay-filter="supplierTable"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/html" id="barContract">
            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
        <script>
            //根据名字搜索
            function SelectName() {
                layui.table.reload('supplierTable', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        name: $("#crReload").val()
                    }
                });
            }
            layui.use(['table', 'form'], function () {
                var table = layui.table;
                var form = layui.form;
                table.render({
                    elem: '#supplierTable'
                    , url: '/api/Produce/GetIngredient'
                    , limit: 15
                    , limits: [15, 25, 35]
                    , title: '用户数据表'
                    , cols: [[
                        { field: 'ingredient_name', title: '配料名单', fixed: 'left', unresize: true }
                        , { field: 'good_name', title: '商品名' }
                        , { field: 'unit', title: '单位', sort: true }
                        , { field: 'sum_money', title: '成本', sort: true }
                        , { field: 'createtime', title: '生成时间', sort: true }
                        , { field: 'remarks', title: '备注', sort: true }
                        , { field: 'user_name', title: '操作人', sort: true }
                        , { fixed: 'right', title: '操作', width: 180, toolbar: '#barContract' }
                    ]]
                    , page: true
                });
                //监听行工具事件
                table.on('tool(supplierTable)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'del') {
                        layer.confirm('真的删除行么',
                            function (index) {
                                $.ajax({
                                    url: `/api/Produce/DeleteIngredientDetail?ingredientid=${data.id}`,
                                    type: 'DELETE',
                                    success: function (res) {
                                        if (res.code === 0) {
                                            layer.msg(res.msg);
                                            obj.del();
                                            layer.close(index);
                                        } else {
                                            layer.msg(res.msg);
                                        }
                                    }
                                });
                            });
                    } else if (obj.event === 'edit') {
                        layer.open({
                            type: 2,
                            title: '编辑',
                            fixed: false, //不固定
                            maxmin: true,
                            content: '/Produce/IngredientDetailUpdate',
                            area: ['70%', '95%'],
                            success: function (layero, index) {
                                var iframe = window['layui-layer-iframe' + index];
                                //调用子页面的全局函数
                                iframe.child(data.id);
                            },//关闭弹出框的回调函数，不管弹出框是手动关闭还是通过脚本进行关闭，都执行
                            end: function () {
                                table.reload('supplierTable');//刷新列表页面
                            }
                        });
                    } else if (obj.event === 'detail') {
                        layer.open({
                            type: 2,
                            title: '查看',
                            fixed: false, //不固定
                            maxmin: true,
                            content: '/Produce/IngredientDetail',
                            area: ['70%', '95%'],
                            success: function (layero, index) {
                                var iframe = window['layui-layer-iframe' + index];
                                //调用子页面的全局函数
                                iframe.child(data.id);
                            }
                        });
                        //xadmin.open('查看', `/Sale/SaleRecordDetail/${data.id}`, 800, 700);
                    }
                });
            });
        </script>
    </div>
</body>
</html>
